package com.ihr360.oneclick.dto.spreadsheet;

import com.ihr360.commons.model.entity.StringIdWithTime;
import com.ihr360.oneclick.dto.OneClickTermDto;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;

/**
 * 电子表格
 *
 * @author tom
 */
@Entity
@Table(name = "tab_spreadsheet")
@DynamicUpdate
public class SpreadsheetDto extends StringIdWithTime implements Serializable {

    private static final long serialVersionUID = -966886752733851734L;

    /**
     * 用户拥有权限
     */
    @OneToOne(mappedBy = "spreadsheet", cascade = CascadeType.ALL, orphanRemoval = true)
    private UserSpreadsheetDto owner;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "term_id")
    private OneClickTermDto term;

    @Column(length = 40, nullable = false)
    private String companyId;

    /**
     * i人事里的用户id
     */
    @Column(length = 40, nullable = false)
    private String creatorId;

    /**
     * sheet标题
     */
    @Column(length = 100)
    private String sheetTitle;

    /**
     * 所属月份
     */
    @Column(nullable = false)
    private Date month;

    /**
     * 状态 （0 草稿数据 1 正式数据）
     */
    @Column
    private Integer status;

    /**
     * row 的发布详情
     */
    @Column(length = 500)
    private String publishDesc;

    @Column(length = 500)
    private String sheetDesc;

    private int rowCount;

    /**
     * 发布总数
     */
    private int publishedCount;

    /**
     * 未发布
     */
    private int unpublishedCount;

    /**
     * 不允许发布
     */
    private int notAllowPublishCount;

    /** 最后发布时间*/
    @Column
    protected Date lastPublishDate;

    /**
     * 电子表格rows
     */
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
    @JoinColumn(name = "spreadsheetId")
    private List<SpreadsheetRowDto> rows;

    /**
     * 固定表格列信息
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "spreadsheetId")
    private List<SpreadsheetColumnDto> columns;

    /**
     * blob，二进制形式的长文本数据,BLOB类型 最大65535=64k
     * 这里面放了合计信息
     */
    @Column(columnDefinition = "blob")
    private byte[] footer;

    /**
     * 薪资类型
     */
    @Column(length = 40, nullable = false)
    private String salaryTypeId;

    /**
     * 微信通知
     */
    @Column
    private Boolean weChatNotice;

    /**
     * 短信通知
     */
    @Column
    private Boolean smsNotice;

    /**
     * 邮箱通知
     */
    @Column
    private Boolean emailNotice;

    /**
     * 附加说明
     */
    @Column(length = 100)
    private String appendedName;

    public SpreadsheetDto() {
    }

    public byte[] getFooter() {
        return footer;
    }

    public void setFooter(byte[] footer) {
        this.footer = footer;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public OneClickTermDto getTerm() {
        return term;
    }

    public void setTerm(OneClickTermDto term) {
        this.term = term;
    }

    public String getCompanyId() {
        return companyId;
    }

    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }

    public String getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    public String getSheetTitle() {
        return sheetTitle;
    }

    public void setSheetTitle(String sheetTitle) {
        this.sheetTitle = sheetTitle;
    }

    public Date getMonth() {
        return month;
    }

    public void setMonth(Date month) {
        this.month = month;
    }

    public String getPublishDesc() {
        return publishDesc;
    }

    public void setPublishDesc(String publishDesc) {
        this.publishDesc = publishDesc;
    }

    public String getSheetDesc() {
        return sheetDesc;
    }

    public void setSheetDesc(String sheetDesc) {
        this.sheetDesc = sheetDesc;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
    }

    public List<SpreadsheetRowDto> getRows() {
        return rows;
    }

    public void setRows(List<SpreadsheetRowDto> rows) {
        this.rows = rows;
    }

    public List<SpreadsheetColumnDto> getColumns() {
        return columns;
    }

    public void setColumns(List<SpreadsheetColumnDto> columns) {
        this.columns = columns;
    }

    public int getPublishedCount() {
        return publishedCount;
    }

    public void setPublishedCount(int publishedCount) {
        this.publishedCount = publishedCount;
    }

    public int getUnpublishedCount() {
        return unpublishedCount;
    }

    public void setUnpublishedCount(int unpublishedCount) {
        this.unpublishedCount = unpublishedCount;
    }

    public int getNotAllowPublishCount() {
        return notAllowPublishCount;
    }

    public void setNotAllowPublishCount(int notAllowPublishCount) {
        this.notAllowPublishCount = notAllowPublishCount;
    }

    public String getFootDataStr() {
        return new String(footer, StandardCharsets.UTF_8);
    }

    public void setFootDataStr(String data) {
        this.footer = data.getBytes();
    }
    
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getLastPublishDate() {
        return lastPublishDate;
    }

    public void setLastPublishDate(Date lastPublishDate) {
        this.lastPublishDate = lastPublishDate;
    }

    public UserSpreadsheetDto getOwner() {
        return owner;
    }

    public void setOwner(UserSpreadsheetDto owner) {
        this.owner = owner;
    }

    public String getSalaryTypeId() { return salaryTypeId; }

    public void setSalaryTypeId(String salaryTypeId) {
        this.salaryTypeId = salaryTypeId;
    }

    public Boolean getWeChatNotice() { return weChatNotice; }

    public void setWeChatNotice(Boolean weChatNotice) { this.weChatNotice = weChatNotice; }

    public Boolean getSmsNotice() { return smsNotice; }

    public void setSmsNotice(Boolean smsNotice) { this.smsNotice = smsNotice; }

    public Boolean getEmailNotice() { return emailNotice; }

    public void setEmailNotice(Boolean emailNotice) { this.emailNotice = emailNotice; }

    public String getAppendedName() { return appendedName; }

    public void setAppendedName(String appendedName) { this.appendedName = appendedName; }
}
